package com.wwz.tcc;

import com.wwz.dao.UserDao;
import io.seata.rm.tcc.api.BusinessActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import java.util.HashMap;

@Service
public class TccUserServiceImpl implements TccUserService{
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserDao userDao;
    @Autowired
    private TransactionTemplate transactionTemplate;
    @Override
    public int insert(BusinessActionContext businessActionContext,String name,long branchId){
        int i = userDao.insert(name,branchId);
        return 1;

    }

    @Override
    public boolean commit(BusinessActionContext businessActionContext) {
        logger.info("======================success======================");
        return true;
    }

    @Override
    public boolean rollback(BusinessActionContext businessActionContext) {
        logger.error("======================error======================");
        try{
            int i = userDao.delete(businessActionContext.getActionContext("branchId").toString());
            return true;
        }catch (Exception e){
            return false;
        }
    }
}
